#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
SSH Port Forwarder 启动脚本
用于简化程序运行流程
"""

import os
import sys
import subprocess

def check_and_install_dependencies():
    """检查并安装必要的依赖库"""
    try:
        import paramiko
        print("✓ paramiko 库已安装")
        return True
    except ImportError:
        print("✗ 缺少 paramiko 库，正在尝试自动安装...")
        try:
            subprocess.check_call([sys.executable, "-m", "pip", "install", "paramiko"])
            print("✓ paramiko 安装成功")
            return True
        except Exception as e:
            print(f"✗ 安装 paramiko 失败: {e}")
            return False

def main():
    """主函数"""
    print("=" * 50)
    print("SSH Port Forwarder 启动程序")
    print("=" * 50)
    
    # 检查依赖
    if not check_and_install_dependencies():
        print("\n请手动安装所需的Python库:")
        print("pip install paramiko")
        sys.exit(1)
    
    # 运行主程序
    try:
        import ssh_port_forwarder
        print("正在启动SSH Port Forwarder...")
        ssh_port_forwarder.main()
    except Exception as e:
        print(f"运行失败: {e}")
        sys.exit(1)

if __name__ == "__main__":
    main()